namespace devtm.Aop.Emit
{
    using System;
    using Mono.Cecil;
    using devtm.Aop.Extensions;

    [Serializable]
    public class EmitArrayCreateExpression : EmitExpression
    {

        private EmitExpressionCollection initializers;
        private EmitExpression sizeExpression;


        public EmitArrayCreateExpression()
        {
            this.initializers = new EmitExpressionCollection();
        }

        public EmitArrayCreateExpression(EmitTypeReference createType, params EmitExpression[] initializers)
        {
            this.initializers = new EmitExpressionCollection();
            this.CreateType = createType;
            this.initializers.AddRange(initializers);
        }

        public EmitArrayCreateExpression(EmitTypeReference createType, EmitExpression size)
        {
            this.initializers = new EmitExpressionCollection();
            this.CreateType = createType;
            this.sizeExpression = size;
        }

        public EmitArrayCreateExpression(EmitTypeReference createType, int size)
        {
            this.initializers = new EmitExpressionCollection();
            this.CreateType = createType;
            this.Size = size;
        }

        public EmitArrayCreateExpression(TypeReference createType, int size)
        {
            this.initializers = new EmitExpressionCollection();
            this.CreateType = new EmitTypeReference(createType);
            this.Size = size;
        }

        //

        //public EmitArrayCreateExpression(Type createType, params EmitExpression[] initializers)
        //{
        //    this.initializers = new ExpressionCollection();
        //    this.createType = new EmitTypeReference(createType);
        //    this.initializers.AddRange(initializers);
        //}

        //public EmitArrayCreateExpression(Type createType, EmitExpression size)
        //{
        //    this.initializers = new ExpressionCollection();
        //    this.createType = new EmitTypeReference(createType);
        //    this.sizeExpression = size;
        //}

        //public EmitArrayCreateExpression(Type createType, int size)
        //{
        //    this.initializers = new ExpressionCollection();
        //    this.createType = new EmitTypeReference(createType);
        //    this.size = size;
        //}

        public EmitTypeReference CreateType { get; set; }

        public EmitExpressionCollection Initializers
        {
            get
            {
                return this.initializers;
            }
        }

        public int Size { get; set; }

        public EmitExpression SizeExpression { get; set; }



        public override void Compile(CilWorker gen)
        {
            gen.NewArray(this.CreateType.Type, Size);
        }


    }
}
